#include "gtest/gtest.h"
#include "Event.h"

USING_NS_B2D

void function_callback(bool& v) { v = true; }

TEST(test_event, can_add_listener)
{
	Event<void(int)> e;

	bool empty = e.isEmpty();
	EXPECT_EQ(true, empty);

	e.addListener([](int){});
	empty = e.isEmpty();
	EXPECT_EQ(false, empty);
}

TEST(test_event, lambda_function_called)
{
	bool result = false;
	Event<void(bool&)> e;
	e.addListener([](bool& v){ v = true; });

	e(result);
	EXPECT_EQ(true, result);
}

TEST(test_event, function_pointer_called)
{
	bool result = false;
	Event<void(bool&)> e;
	e.addListener(function_callback);

	e(result);
	EXPECT_EQ(true, result);
}

TEST(test_event, method_pointer_called)
{
	struct Dummy
	{
		void method_callback(bool& v) { v = true; }
	}
	myclass;

	bool result = false;
	Event<void(bool&)> e;
	e.addListener(&myclass, &Dummy::method_callback);

	e(result);
	EXPECT_EQ(true, result);
}